package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ95 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle9501(cmd);
            case 0x05:
                return handle9505(cmd);
            case 0x08:
                return handle9508(cmd);
            case 0x09:
                return handle9509(cmd);
            case 0x0A:
                return handle950A(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle950A(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储音视频回放控制");
        builder.append("\r\n");
        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");

        int way = cmd.readInt(1);
        HashMap<Integer,String> wayList = new HashMap<>();
        wayList.put(0,"正常回放");
        wayList.put(1,"暂停回放");
        wayList.put(2,"结束回放");
        wayList.put(3,"快进回放");
        wayList.put(4,"关键帧快退回放");
        wayList.put(5,"拖动回放");
        wayList.put(6,"关键帧播放");

        builder.append("回放控制("+way+")："+wayList.getOrDefault(way,"未定义"));
        builder.append("\r\n");

        int multiple = cmd.readInt(1);
        HashMap<Integer,String> multipleList = new HashMap<>();
        multipleList.put(0,"无效");
        multipleList.put(1,"1倍");
        multipleList.put(2,"2倍");
        multipleList.put(3,"4倍");
        multipleList.put(4,"8倍");
        multipleList.put(5,"16倍");
        builder.append("快进或快退倍数-仅回放方式为3或4时有效("+multiple+")："+multipleList.getOrDefault(multiple,"未定义"));
        builder.append("\r\n");

        builder.append("拖动回放位置(回放控制为5时有效)："+cmd.readBCD(6));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9509(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储音视频回放请求");
        builder.append("\r\n");

        builder.append("服务器IP地址:"+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");

        builder.append("TCP 端口:"+cmd.readWord());
        builder.append("\r\n");

        builder.append("UDP 端口:"+cmd.readWord());
        builder.append("\r\n");

        builder.append("逻辑通道号:"+cmd.readInt(1));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"音视频");
        list.put(1,"音频");
        list.put(2,"视频");
        list.put(3,"视频或音视频");
        builder.append("音视频属性:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"主存储器或灾备存储器");
        list.put(1,"主存储器");
        list.put(2,"备份存储器");
        builder.append("存储器类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"正常传输");
        list.put(1,"快进跳帧传输；(暂不支持)");
        list.put(2,"关键帧快退传输；(暂不支持)");
        list.put(3,"关键帧传输；(暂不支持)");
        list.put(4,"单帧传输；(暂不支持)");
        builder.append("传输方式:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        int multiple = cmd.readInt(1);
        HashMap<Integer,String> multipleList = new HashMap<>();
        multipleList.put(0,"无效");
        multipleList.put(1,"1倍");
        multipleList.put(2,"2倍");
        multipleList.put(3,"4倍");
        multipleList.put(4,"8倍");
        multipleList.put(5,"16倍");
        builder.append("快进或快退倍数-仅回放方式为1或2时有效("+multiple+")："+multipleList.getOrDefault(multiple,"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(1,"主码流");
        list.put(2,"子码流");
        builder.append("码流类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("开始时间（传输方式为4时表示单帧传输时刻，终端传输距离该时刻最近的关键帧）:"+cmd.readBCD(2));
        builder.append("\r\n");

        builder.append("终止时间（0表示一直回放，传输方式为4时该字段无效）:"+cmd.readBCD(2));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9508(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:终端搜索月历信息列表");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"音视频");
        list.put(1,"音频");
        list.put(2,"黑匣子");
        list.put(3,"音视频");
        list.put(4,"报警日志");
        list.put(5,"用户日志");
        builder.append("查询属性:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(1,"主码流");
        list.put(2,"子码流");
        builder.append("码流类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(1,"主存储器");
        list.put(2,"备份存储器");
        builder.append("存储位置:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"所有录像");
        list.put(1,"报警");
        builder.append("查询模式:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("开始时间:"+cmd.readBCD(2));
        builder.append("\r\n");

        builder.append("终止时间:"+cmd.readBCD(2));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9505(SZ_2021Cmd cmd){
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储音视频检索");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(1,"音频");
        list.put(2,"视频");
        list.put(3,"音视频");
        builder.append("查询属性:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(1,"主码流");
        list.put(2,"子码流");
        builder.append("码流类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(1,"主存储器");
        list.put(2,"备份存储器");
        builder.append("存储位置:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("逻辑通道号:"+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("报警类型:"+cmd.readBCD(64));
        builder.append("\r\n");

        builder.append("开始时间:"+cmd.readBCD(6));
        builder.append("\r\n");

        builder.append("终止时间:"+cmd.readBCD(6));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9501(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:实时音视频传输请求");
        builder.append("\r\n");

        builder.append("服务器IP地址:"+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");

        builder.append("服务器视频通道监听端口号（TCP）:"+cmd.readInt(2));
        builder.append("\r\n");

        builder.append("服务器视频通道监听端口号（UDP）:"+cmd.readInt(2));
        builder.append("\r\n");

        builder.append("逻辑通道号:"+cmd.readInt(1));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"音视频");
        list.put(1,"视频");
        list.put(2,"双向对讲");
        list.put(3,"监听");
        list.put(4,"中心广播");
        list.put(5,"透传");
        builder.append("数据类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.put(0,"子码流");
        list.put(1,"主码流");
        builder.append("码流类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }


}
